package com.example.day9_sqlite;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;


public class HttpUtils {

    public static String doGet(String url){
            InputStream is = null;
            try {
                HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
                connection.setRequestMethod("GET");
                if(connection.getResponseCode()==HttpURLConnection.HTTP_OK){
                   is = connection.getInputStream();
                    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
                    StringBuffer sb = new StringBuffer();
                   String str = "";
                   while ((str = reader.readLine())!=null){
                       sb.append(str);
                   }
                   return sb.toString();
                }

            } catch (IOException e) {

            }finally {
                if(is!=null){
                    try {
                        is.close();
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
            return null;
    }

}
